home *** CD-ROM | disk | FTP | other *** search
- Path: news1.h1.usa.pipeline.com!usenet
- From: grantp@usa.pipeline.com(Pete)
- Newsgroups: comp.lang.c++
- Subject: Re: Converting integer to char/string?
- Date: 5 Feb 1996 21:24:56 GMT
- Organization: Kalevi, Inc.
- Message-ID: <4f5sj8$5f8@news1.usa.pipeline.com>
- NNTP-Posting-Host: 38.8.60.2
- X-PipeUser: grantp
- X-PipeHub: usa.pipeline.com
- X-PipeGCOS: (Pete)
- X-Newsreader: Pipeline USA v3.3.0
-
- On Feb 05, 1996 17:25:03 in article <Converting integer to char/string?>,
- 'Gilbert Banks <gilbertb@bnr.ca>' wrote:
-
-
- >What is the function and header for converting an integer to char or
- string?
- >I think the header is <stdlib.h>.
-
- Nope, not stdlib.h.
-
- First, integer to char:
- int i = somenum();
- char c = i;
-
- Second, integer to string:
-
- C C++
- ------------------ ---------------------
- #include <stdio.h> #include <ostrstream.h>
- char s[25]; ostrstream os;
- int n = somenum(); int n = somenum();
- sprintf("%d", n); os << n << ends;
-
- If you are on a DOS or other Inel machine, change the C++
- version to read #include <ostrstrea.h>
-
- --
- Pete Grant
- Kalevi, Inc.
- Object Oriented Software Development
-